import Vue from 'vue'
import VueRouter from 'vue-router'
import segmentation from '/public/configuration'
// import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  // http://192.168.31.3:8045/#/login_auth?redirectUrl=http://192.168.20.249:8081
  {
    path: '/',
    name: 'IndexPage',
    component: () => import('../views/IndexPage.vue')
  },
  {
    path: '/Mainpage',
    name: 'Mainpage',
    component: () => import('../views/MainPage.vue'),
    children:[

      //相当于mainpage这个vue文件里的<router-view>里面渲染的内容，url就是/mainpange/test1
      {
        name: 'testpage',
        path: 'test1',
        component: ()=> import('../components/HelloWorld.vue')
      },
      {
          name: 'FGSMpage',
          path: 'WBT/FGSM',
          component: ()=> import('../components/FSGMTable.vue')
      },
      {
        name: 'CWpage',
        path: 'WBT/CW',
        component: ()=> import('../components/CWTable.vue')
      },
      {
        name: 'PGDpage',
        path: 'WBT/PGD',
        component: ()=> import('../components/PGDTable.vue')
      },
      {
        name: 'DeepFoolpage',
        path: 'WBT/DeepFool',
        component: ()=> import('../components/DeepFoolTable.vue')
      },
      {
        name: 'AdvIntropage',
        path: 'AdvIntro',
        component: ()=> import('../components/AdvIntro.vue')
      },
      {
        name: 'SIMPage',
        path: 'BBT/SIM',
        component: ()=> import('../components/SIMTable.vue')
      },
      {
        name: 'BAPage',
        path: 'BBT/BA',
        component: ()=> import('../components/BATable.vue')
      },
      {
        name: 'TestPage',
        path: 'TestPage',
        component: ()=> import('../components/TestTable.vue')
      },

    ]
  }
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  // next();
  // let aaa = prompt("", "");
  // if(aaa == '456'){
  //
  // }


  if(!segmentation.direct){
    if (window.opener && localStorage.getItem('one') == undefined) {
      localStorage.setItem('one',0)
      window.location.href='http://192.168.31.3:8045/#/login_auth?redirectUrl=http://192.168.20.249:8081'
    }
    else if(localStorage.getItem('one') != 0){
      if(localStorage.getItem('one') != 0){
        window.location.href='http://192.168.31.3:8045/#/'
      }
    }else{
      if(sessionStorage.getItem('subSystems') != null){
        next();
      }else{
        if(localStorage.getItem('one') != 0){
          window.location.href='http://192.168.31.3:8045/#/'
        }
      }
    }
  }else{
    next();
  }

});

export default router
